<%
if (session.getAttribute("username") == null) {
	%><jsp:forward page="login.jsp" /><%
}
%>
<jsp:useBean id="user" class="bean.PollUser" scope="request" />
<jsp:setProperty name="user" property="*"/>
<%@ page language="java" contentType="text/html; charset=GBK"
	pageEncoding="GBK" import="bean.PollUser, model.PollUserImpl, connection.DbConnection, java.sql.*" %>

<%
	// Get user bean all setup...
	//session.setAttribute("user",user);
	
	// Redirect to login page if user not logged in
	if (session.getAttribute("username") == null) {
		response.sendRedirect("login.jsp");
	}
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK"> 
<link rel="stylesheet" href="style/stylesheet.css" type="text/css" >
<title>dbPoll/Poll Administration: Define Poll</title>
<script type="text/javascript">

    function check(form){

        // Clear success msgs
        document.getElementById("success_msg").innerHTML = "";
           
        if(document.forms.form1.define_poll.value==""){
            document.getElementById("define_poll_msg").innerHTML = "<div class=\"error\" style=\"display: block; \" >* Please add poll definition. </div>";
            document.forms.form1.define_poll.focus();   
            return false;   
        } else {
        	document.getElementById("define_poll_msg").innerHTML = "";
        }
        return true;
    }


</script>
</head>

<body onload="user_type();">
<div class="bg">
<div class='content' >
<jsp:include page="nav.jsp" />
	<div id="title" class= "pagetitle">Poll Administration<input type="button" style="font-size:8pt;color:white;background-color:lightblue;border:none;" value="Quick Help"></div>
	<div class="entrytitle">
	Define Poll
	<div class="entry">
	<form action="DefinePollServlet" method="post" name="form1">
		<table>
			<tr><td width="100">Poll Creator</td><td><select name="poll_creator" ">
			<%	
				DbConnection db = new DbConnection();
				String sql = "Select username from PollUser where accessibility = 3";
				ResultSet rs = db.doSelect(sql);
				while (rs.next()) {
					out.println("<option value=\""+rs.getString("username")+"\">"+rs.getString("username")+"</option>");
				}
				db.close();
			 %>
			</select></td></tr>

			 	 
			<tr><td>Define Poll... </td><td><textarea cols="100" rows="5" name="define_poll">I would like you to make a poll with...</textarea></td><td id="define_poll_msg" ></td></tr>
			 
			 
			<tr> <td></td><td><input type="submit" name="submit" class="button" value="Send poll definition to poll creator" onclick="return check(this);" /></td> </tr>
			
			</table>
			
			</form>
			<div id="success_msg" >   
			<%	
				// Check for success/failure message
				if (session.getAttribute("define_poll_success") != null && session.getAttribute("define_poll_success").equals("t")) {
					out.println("<div class=\"note\" style=\"display: inline;\" >* Poll successfully defined! </div>");
				}
				if (session.getAttribute("define_poll_success") != null && session.getAttribute("define_poll_success").equals("f")) {
					out.println("<div class=\"error\" style=\"display: inline;\" >* Poll definition unsuccessful! </div>");
				}
				//<input type="text" size="100" name="define_poll"/>
			%>
			</div>	

</div>
</div>
</div>



</div>
<style>
#onlinehelp{position:absolute;display:none;z-index:2;border:5px solid lightblue;background-color:#33aecc;color:white}
</style>
<div id="onlinehelp"></div>
<script>
var demo = document.getElementById("title");
var gg = demo.getElementsByTagName("input");
var ei = document.getElementById("onlinehelp");
for(i=0; i<gg.length; i++){
 var ts = gg[i];
 ts.onmousemove = function(event){
  event = event || window.event;
  ei.style.display = "block";
  ei.innerHTML = '1. Select a poll creator form dropdown list<br>2. Input the Definition for the poll and press the submit button to send it to the selecting poll creator<br> *For more help please click the button';
  ei.style.top  = document.body.scrollTop + event.clientY  -65 + "px";
  ei.style.left = document.body.scrollLeft + event.clientX  +35 + "px";
 }
 ts.onmouseout = function(){
  ei.innerHTML = "";
  ei.style.display = "none";
 }
 ts.onclick = function(){
	 location.href="/DBP/OnlineHelp/Define.jsp";
 }
}
</script>
</body>
</html>